home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: MegaDisc
/
MegaDisc 34 (1993-06)(MegaDisc Digital Publishing)(AU)(Disk 1 of 2)[WB].zip
/
MegaDisc 34 (1993-06)(MegaDisc Digital Publishing)(AU)(Disk 1 of 2)[WB].adf
/
Programs
/
IntConv32
/
itoa32.asm
< prev
next >
Wrap
Assembly Source File
|
1993-06-21
|
1KB
|
76 lines
; (C) 1993 Peter Thompson
; 32 (un|%)signed integer to base 10 string conversion.
INCLUDE "intdefs.i"
IFD ASM_ENTRY
INCLUDE "intconv32.i"
ENDIF
IFD STKARGS
PUBLIC _utoa32
_utoa32: ;C stkargs entry
move.l 8(sp),d0 ;C uint32
move.l 4(sp),a0 ;C char *
bra ua32
ENDIF
IFD STKARGS
PUBLIC _itoa32
_itoa32: ;C stkargs entry
move.l 8(sp),d0 ;C int32
move.l 4(sp),a0 ;C char *
ENDIF
IFD REGARGS
PUBLIC @itoa32
@itoa32: ;C regargs entry
ENDIF
i2a32: tst.l d0
bpl ua32
PutCh #'-'
neg.l d0
IFD REGARGS
PUBLIC @utoa32
@utoa32: ;C regargs entry
ENDIF
u2a32:
ua32: ; converts 32 bit unsigned integer to base 10 string.
push Dlim/Digit
lea u32tbl(PC),Table
moveq #8,Dlim ; # of items in u32tbl - 1
ls32: cmp.l (Table)+,d0 ; compare to table entries
dbcc Dlim,ls32 ; until table <= number or out of table
add.w #1,Dlim
beq pru32a ; 0-10 take this branch
subq.l #4,Table ; overshot : let's fix it.
pru32a: move.l (Table)+,d1 ; print 32 bit unsigned integer.
moveq #%00001111+'0',Digit
pru32b: sub.l d1,d0 ; linear faster for dividend < 10.
dbcs Digit,pru32b
add.l d1,d0
eor.b #%00001111,Digit ; magic
PutCh Digit
dbra Dlim,pru32a
PutCh #0 ; terminate string.
pop Dlim/Digit
move.l a0,d0 ;C return value
rts
u32tbl: dc.l $3B9ACA00
dc.l $05F5E100
dc.l $00989680
dc.l $000F4240
dc.l $000186A0
dc.l $00002710
dc.l $000003E8
dc.l $00000064
dc.l $0000000A
dc.l $00000001
END